﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using NUnit.Framework;

namespace JingQiao.Ads.Infrastructure.Data.EF.Test
{
    using Domain.Model;
    using Domain.Model.DomainObject;
    using Domain.Model.Repository;
    using Infrastructure.Data.EF.DomainObject;
    using Infrastructure.Data.EF.Repository;
    using Infrastructure;

    [TestFixture]
    [Platform("Net-4.0")]
    public class AdvertisementRepositoryTest
    {
        private AdsContext _context;

        public AdvertisementRepositoryTest()
        {
            this._context = new AdsContext();
        }

        [SetUp]
        public void Start()
        {
            this._context = new AdsContext();
        }

        [TearDown]
        public void Finish()
        {
            this._context.Dispose();
        }

        [Test]
        public void Add()
        {
            IAdvertisement ad = new Advertisement();
            ad.AttachmentUrl = "www.example.com";
            ad.CreateDate = DateTime.Now;
            ad.Creator = "tom";
            ad.LinkUrl = "www.ads.com";
            ad.Sequence = 10;
            ad.Status = 1;
            ad.Title = "the first ads";
            ad.Type = 1;
            ad.UnionAdHtml = string.Empty;
            ad.DestPositionAd = null;

            IAdvertisementRepository adRep = new AdvertisementRepository(this._context);
            adRep.Add(ad);            
            this._context.Commit();

            int count = adRep.FindAll(10, 0).Total;
            Assert.AreEqual(1, adRep.CountAll());
        }
    }
}
